package com.library.admin.modules.user.bo;

import com.library.admin.modules.user.entity.User;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * 登录用户身份信息
 *
 * @author: xyh
 * @create: 2023-10-03
 **/
@Data
public class CustomUserDetails implements UserDetails {

    private final User user;

    public CustomUserDetails(User user) {
            this.user = user;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    public String getRoles() {
        return user.getRoleIds();
    }

    @Override
    public boolean isAccountNonExpired() {
        // 返回账户是否未过期
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        // 返回账户是否未被锁定
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        // 返回凭证是否未过期
        return true;
    }

    @Override
    public boolean isEnabled() {
        //账号正常的
        return user.getStatus().equals(0);
    }
}
